<extend name="Public/base" />

<block name="body">
	<!-- 标题栏 -->
	<div class="main-title">
		<h2>订单列表</h2>
	</div>
	<div class="cf">
		<div class="fl">
			<a class="btn fileDown" href="javascript::">导 出</a>
		</div>
		<div class="search-form fr cf">
			<div class="sleft">
				<input type="text" name="order_id" class="search-input" value="{:I('order_id')}" placeholder="请输入订单号">
				<a class="sch-btn" href="javascript:;" id="search" url="{:U('Order/index')}"><i class="btn-search"></i></a>
        		<label>订单状态：</label>
        		<select name="take_status" id="take_status" onchange="changeOrder(this);">
        			<option value="-1">--请选择--</option>
        			<option value="order|0" <if condition="I('status') eq 'order|0'">selected="selected"</if>>等待买家付款</option>
        			<option value="order|2" <if condition="I('status') eq 'order|2'">selected="selected"</if>>等待发货</option>
        			<option value="order|3" <if condition="I('status') eq 'order|3'">selected="selected"</if>>已发货</option>
        			<option value="return|2" <if condition="I('status') eq 'return|2'">selected="selected"</if>>退款中</option>
        			<option value="order|4" <if condition="I('status') eq 'order|4'">selected="selected"</if>>成功的订单</option>
        			<option value="order|5" <if condition="I('status') eq 'order|5'">selected="selected"</if>>关闭的订单</option>
        		</select>
			</div>
            <div class="btn-group-click adv-sch-pannel fl">
                <button class="btn">高 级<i class="btn-arrowdown"></i></button>
                <div class="dropdown cf">
                	<div class="row">
                		<label>订单时间：</label>
                		<input type="text" id="time-start" name="time-start" class="text input-2x" value="" placeholder="起始时间" value="{:I('time-start')}" /> -      
                        <div class="input-append date" id="datetimepicker"  style="display:inline-block">
                            <input type="text" id="time-end" name="time-end" class="text input-2x" value="" placeholder="结束时间" value="{:I('time-end')}" />
                            <span class="add-on"><i class="icon-th"></i></span>
                        </div>
                	</div>
                </div>
            </div>
		</div>
    </div>
    <!-- 数据列表 -->
    <div class="data-table table-striped">
	<table class="">
    <thead>
        <tr>
		<th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
		<th class="">序号</th>
		<th class="">订单号</th>
		<th class="">用户ID</th>
		<th class="">实付金额</th>
		<th class="">交易状态</th>
		<th class="">收货状态</th>
		<th class="">退货状态</th>
		<th>订单创建时间</th>
		<th>物流订单</th>
		<th>物流来源</th>
		<th>操作</th>
		</tr>
    </thead>
    <tbody>
		<notempty name="_list">
		<volist name="_list" id="vo">
		<tr>
            <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
			<td>{$key + 1} </td>
			<td>{$vo.order_id}</td>
			<td>{$vo.client_id}</td>
			<td>￥{$vo.pock_money|default=0}</td>
			<td did="{$vo.order_status}">
				<switch name="vo.order_status">
					<case value="0">等待买家付款</case>
					<case value="1">付款确认中</case>
					<case value="2">买家已付款</case>
					<case value="3">卖家已发货</case>
					<case value="4">交易成功</case>
					<case value="5">交易关闭</case>
				</switch>
			</td>
			<td did="{$vo.take_status}">
				<switch name="vo.take_status">
					<case value="0">---</case>
					<case value="1">未收货</case>
					<case value="2">确认收货</case>
				</switch>
			</td>
			<td did="{$vo.return_status}">
				<a href="{:U('return_index', array('order_id' => $vo['order_id']))}">退货详情<font color="red">({$vo.order_id|getReturnCount=###})</font></a> 
			</td>
			<td>{$vo.ctime|getDateFormat=###}</td>
			<td>{$vo.wl_order|default=''}</td>
			<td>{$vo.wl_name|default=''}</td>
			<td>
				<if condition="$vo.order_status eq 2">
					<!-- <a href="{:U('sendGoods', array('order_id' => $vo['order_id'], 'id' => $vo['id'], 'order_status' => 3))}" class="ajax-get">发货</a> -->
					<a href="{:U('send_detail', array('order_id' => $vo['order_id']))}">发货</a>
				<else />
					<input type="hidden" id="order_{$vo.order_id}" value="{:U('detail', array('order_id' => $vo['order_id']))}">
					<a href="{:U('del', array('order_id' => $vo['order_id']))}" class="ajax-get">删除</a>
					<a href="{:U('send_detail', array('order_id' => $vo['order_id'], 'type' => 'look'))}"">查看详细</a>
					<a href="{:U('bull_address', array('take_id' => $vo['take_id']))}">收货地址</a>
				</if>
            </td>
		</volist>
		<else/>
		<td colspan="13" class="text-center"> aOh! 暂时还没有内容! </td>
		</notempty>
	</tbody>
    </table>
	</div>
    <div class="page">
        {$_page}
    </div>
</block>

<block name="script">
	<link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
	<php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
	<link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
	<script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
	<script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

	<script type="text/javascript">
		$(function(){
			//搜索功能
			$("#search").click(function(){
				var url = $(this).attr('url');
				//var status = $("#sch-sort-txt").attr("data");
		        var query  = $('.search-form').find('input').serialize();
		        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
		        query = query.replace(/^&/g,'');
				if(status != ''){
					query = 'status=' + status + "&" + query;
		        }
		        if( url.indexOf('?')>0 ){
		            url += '&' + query;
		        }else{
		            url += '?' + query;
		        }
				window.location.href = url;
			});

			/* 状态搜索子菜单 */
			$(".search-form").find(".drop-down").hover(function(){
				$("#sub-sch-menu").removeClass("hidden");
			},function(){
				$("#sub-sch-menu").addClass("hidden");
			});
			$("#sub-sch-menu li").find("a").each(function(){
				$(this).click(function(){
					var text = $(this).text();
					$("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
					$("#sub-sch-menu").addClass("hidden");
				})
			});

		    //回车自动提交
		    $('.search-form').find('input').keyup(function(event){
		        if(event.keyCode===13){
		            $("#search").click();
		        }
		    });

		    $('#time-start').datetimepicker({
		        format: 'yyyy-mm-dd',
		        language:"zh-CN",
			    minView:2,
			    autoclose:true
		    });

		    $('#datetimepicker').datetimepicker({
		       format: 'yyyy-mm-dd',
		        language:"zh-CN",
		        minView:2,
		        autoclose:true,
		        pickerPosition:'bottom-left'
		    })

			//原始操作
			var y_html_1 = '',
				y_html_2 = '',
				y_html_3 = '',
				y_html_4 = '',
				y_html_5 = ''
				y_html_6 = '';	

			$('.data-table').on('click', '.up_data', function(){
				var tr_index = $(this).parent().parent().index(),	//获取当前tr所在的位置
					id = $(this).attr('did');	
				changeText(tr_index, id);
			}).on('click', '.sureData', function(){
				var order_status = $('#order_status option:selected').val(),
					order_status_text = $('#order_status option:selected').text(),
					take_status = $('#take_status option:selected').val(),
					take_status_text = $('#take_status option:selected').text(),
					// return_status = $('#return_status option:selected').val(),
					// return_status_text = $('#return_status option:selected').text(),
					get_url = "{:U('update_status')}",
					id = $(this).attr('did'),
					index_id = $(this).attr('index_id'),
					wl_order = $('#wl_order').val(),
					wl_name = $('#wl_name').val();
				$.get(
					get_url, 
					{
						id: id,
						order_status: order_status,
						take_status: take_status,
						// return_status: return_status,
						wl_order: wl_order,
						wl_name: wl_name
					}, function(r){
						if(r.status){
							recoverHandle(index_id, order_status, order_status_text, take_status, take_status_text, wl_order, wl_name);
						}else{
							alert(r.info);
						}
					}, 'json');
			});

			$('.fileDown').click(function(){
				var url = "{:U('index')}",
					take_status = $('#take_status option:selected') .val();//选中的值
			 	if( url.indexOf('?')>0 ){
		            url += '&status=' + take_status + '&show_type=down';
		        }else{
		            url += '?status=' + take_status + '&show_type=down';
		        }
				window.location.href = url;

			});
		});
	

		function changeText(index, id){
			//支付方式
			y_html_1 = $('.data-table table tbody tr').eq(index).find('td').eq(6).html();
			y_html_2 = $('.data-table table tbody tr').eq(index).find('td').eq(7).html();
			// y_html_3 = $('.data-table table tbody tr').eq(index).find('td').eq(8).html();
			y_html_4 = $('.data-table table tbody tr').eq(index).find('td').eq(10).html();	//物流订单
			y_html_5 = $('.data-table table tbody tr').eq(index).find('td').eq(11).html();	//物流来源
			y_html_6 = $('.data-table table tbody tr').eq(index).find('td').eq(12).html();	//操作
			var obj = $('.data-table table tbody tr').eq(index).find('td');
			//交易状态	
			obj.eq(6).html(
				'<select name="order_status" id="order_status">'+
					'<option value="0">等待买家付款</option>'+
					'<option value="1">付款确认中</option>'+
					'<option value="2">买家已付款</option>'+
					'<option value="3">卖家已发货</option>'+
					'<option value="4">交易成功</option>'+
					'<option value="5">交易关闭</option>'+
				'</select>'
			);		
			//收货状态
			obj.eq(7).html(
				'<select name="take_status" id="take_status">'+
					'<option value="0">---</option>'+
					'<option value="1">未收货</option>'+
					'<option value="2">确认收货</option>'+
				'</select>'
			);	
			//退货状态
			// obj.eq(8).html(
			// 	'<select name="return_status" id="return_status">'+
			// 		'<option value="0">---</option>'+
			// 		'<option value="1">未退货</option>'+
			// 		'<option value="2">退货中</option>'+
			// 		'<option value="3">退货完成</option>'+
			// 	'</select>'
			// );
			//物流订单
			obj.eq(10).html('<input type="text" name="wl_order" id="wl_order" value="'+obj.eq(10).html()+'">');
			//物流来源
			obj.eq(11).html('<input type="text" name="wl_name" id="wl_name" value="'+obj.eq(11).html()+'">');
			//修改操作状态
			obj.eq(12).html(
				'<a href="javascript:void(0);" class="sureData" did="'+id+'" index_id="'+index+'">确定</a>'+
				'<a href="javascript:recoverHandle('+index+')" style="margin-left:10px;">返回</a>'
			);	

			//设置选项的值
			$("#order_status").val(parseInt(obj.eq(6).attr('did')));
			$("#take_status").val(parseInt(obj.eq(7).attr('did')));
			// $("#return_status").val(parseInt(obj.eq(8).attr('did')));
			
		}

		//恢复操作
		function recoverHandle(index, order_status, order_status_text, take_status, take_status_text, wl_order, wl_name){
			$('.data-table table tbody tr').eq(index).find('td').eq(6).attr('did', order_status);
			$('.data-table table tbody tr').eq(index).find('td').eq(6).html(order_status_text == undefined ? y_html_1 : order_status_text);
			$('.data-table table tbody tr').eq(index).find('td').eq(7).attr('did', take_status);
			$('.data-table table tbody tr').eq(index).find('td').eq(7).html(take_status_text == undefined ? y_html_2 : take_status_text);
			// $('.data-table table tbody tr').eq(index).find('td').eq(8).attr('did', return_status);
			// $('.data-table table tbody tr').eq(index).find('td').eq(8).html(return_status_text == undefined ? y_html_3 : return_status_text);
			$('.data-table table tbody tr').eq(index).find('td').eq(10).html(wl_order == undefined ? y_html_4 : wl_order);
			$('.data-table table tbody tr').eq(index).find('td').eq(11).html(wl_name == undefined ? y_html_5 : wl_name);
			$('.data-table table tbody tr').eq(index).find('td').eq(12).html(y_html_6);
		}
		function changeOrder(obj){
			var url = "{:U('index')}";
			if( url.indexOf('?')>0 ){
				url += '&status=' + obj.value;
			}else{
				url += '?status=' + obj.value;
			}
			window.location.href = url;
		}

	    //导航高亮
	    highlight_subnav('{:U('Order/index')}');
	</script>
</block>

